%locationStart and orientationStart
p = [0 0 0]'; R = eye(3);
%TransformationMatrix Start
Tstart = [[R p];[0 0 0 1]];
endAngle = -90; time = 1;
totalSteps = -endAngle/stepSize * 4 + 4 ;
path = sin(linspace(0,2*pi,totalSteps))/2 + 1;
for angle = 0:-stepSize:endAngle
Rcurrent = rotY(angle*pi/180);
Tlast_to_now = [[Rcurrent [0 0 0]'];[0 0 0 1]];
Tnow = Tstart*Tlast_to_now;
darkness = angle/endAngle/1.15;
drawAxis2(Tnow,darkness); %location,orientation,darkness,axisLimits)
% Include the current angle in the title
title(sprintf('Rotation about the Y Axis by %0.2f degrees',angle),'Interpreter','Latex');
xlim([-1 1]); ylim([-1 1]); zlim([-0.1 3]);
saveFrame('animation.gif',time)
Rcurrent = rotY(-90*pi/180);
Tstart = [[Rcurrent [0 0 0]'];[0 0 0 1]];
for angle = 0:-stepSize:endAngle
Rcurrent = rotZ(angle*pi/180);
Tlast_to_now = [[Rcurrent [0 0 0]'];[0 0 0 1]];
Tnow = Tstart*Tlast_to_now;
darkness = angle/endAngle/1.15;
drawAxis2(Tnow,darkness); %location,orientation,darkness,axisLimits)
title(sprintf('Rotation about the Z Axis by %0.2f degrees',angle),'Interpreter','Latex');
xlim([-1 1]); ylim([-1 1]); zlim([-0.1 3]);
saveFrame('animation.gif',time)
Rcurrent = rotY(-90*pi/180)*rotZ(-90*pi/180);
Tstart = [[Rcurrent [0 0 0]'];[0 0 0 1]];
for angle = 0:-stepSize:endAngle
Rcurrent = rotX(angle*pi/180);
Tlast_to_now = [[Rcurrent [0 0 0]'];[0 0 0 1]];
Tnow = Tstart*Tlast_to_now;
darkness = angle/endAngle/1.15;
drawAxis2(Tnow,darkness); %location,orientation,darkness,axisLimits)
title(sprintf('Rotation about the Z Axis by %0.2f degrees',angle),'Interpreter','Latex');
xlim([-1 1]); ylim([-1 1]); zlim([-0.1 3]);
saveFrame('animation.gif',time)
Rcurrent = rotY(-90*pi/180)*rotZ(-90*pi/180)*rotX(-90*pi/180);
Tstart = [[Rcurrent [0 0 0]'];[0 0 0 1]];
for angle = 0:-stepSize:endAngle
Rcurrent = rotY(angle*pi/180);
Tlast_to_now = [[Rcurrent [0 0 0]'];[0 0 0 1]];
Tnow = Tstart*Tlast_to_now;
darkness = angle/endAngle/1.15;
drawAxis2(Tnow,darkness); %location,orientation,darkness,axisLimits)
title(sprintf('Rotation about the Y Axis by %0.2f degrees',angle),'Interpreter','Latex');
xlim([-1 1]); ylim([-1 1]); zlim([-0.1 3]);
saveFrame('animation.gif',time)
function drawAxis2(T,darkness)
Isometric = [-45 35.264];
f = 1+darkness; %Darkness should be from 0 to 1
color = [ [182, 2, 8]/182/f ; [59, 114, 29]/114/f ; [4, 110, 143]/143/f ];
orientation = T(1:3,1:3);
quiver3(location(1),location(2),location(3),vec(1),vec(2),vec(3),'LineWidth',2,'Color',color(i,:));
%Viewing and Plot Settings
xlabel('x', 'Interpreter', 'Latex'),ylabel('y', 'Interpreter', 'Latex'),zlabel('z', 'Interpreter', 'Latex')
function axisLimits = initializeAxisLimits()
axisLimits.xmin=-0.01; axisLimits.xmax=0.1; axisLimits.ymin=-0.01; axisLimits.ymax=0.1; axisLimits.zmin=-0.01; axisLimits.zmax=0.1;
function [axisLimits] = checkAxisLimits(p_now,axisLimits);
x = p_now(1); y = p_now(2) ; z = p_now(3);
%Check the current point in 3D space
%Goal of the function is to get the maximum and minimum x y z for all time
elseif x < axisLimits.xmin
elseif y < axisLimits.ymin
elseif z < axisLimits.zmin
function saveFrame(filename,t)
[imind,cm] = rgb2ind(im,256);
if t == 1 %create the file if t is 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
%Could write a preprogrammed image here
if t > 1 %just append to the file if its not t = 1
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.05)%,...
% useful for rigid-body motions
% takes an angle of rotation (radians)
% returns the corresponding rotation matrix, about the Z axis
rot = [1,0,0;0,cos(a),-sin(a);0,sin(a),cos(a)];
% useful for rigid-body motions
% takes an angle of rotation (radians)
% returns the corresponding rotation matrix, about the Y axis
rot = [cos(b),0,sin(b);0,1,0;-sin(b),0,cos(b)];
% useful for rigid-body motions
% takes an angle of rotation (radians)
% returns the corresponding rotation matrix, about the Z axis
rot= [cos(g),-sin(g),0;sin(g),cos(g),0;0,0,1];